<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>

	<head>
		<meta charset="utf-8"  />
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>商品列表</title>
		<link rel="stylesheet" href="<%=request.getContextPath()%>/resources/css/bootstrap.min.css" type="text/css" />
		<script src="<%=request.getContextPath()%>/resources/js/jquery-1.11.3.min.js" type="text/javascript"></script>
		<script src="<%=request.getContextPath()%>/resources/js/bootstrap.min.js" type="text/javascript"></script>
		<script type="text/javascript" src="<%=request.getContextPath()%>/resources/js/jquery-heima-0.0.1.js" ></script>
		<!-- 引入自定义css文件 style.css -->
		<script>

			$(function(){
				if(HM.getParameter("cid")==""||HM.getParameter("cid")==null){
					HM.ajax("<%=request.getContextPath()%>/productServlet","method=foundByNamePage&search=<%=request.getParameter("search")%>&pagenum="+HM.getParameter("pagenum"),function(data){
						if(data.code == 1)
							var str = "";
							var list = data.obj.list;
							$.each(list, function(index,ele) {
								str+="<div style=\"height:250px;\" class=\"col-md-2 col-sm-4 col-xs-6\"><a href=\"<%=request.getContextPath()%>/productServlet?method=getOneProduct&pid="+ele.pid+"\"><img src=\"<%=request.getContextPath()%>/"+ele.pimage+"\" width=\"170px\" height=\"170px\" style=\"display: inline-block;\"></a><p><a href=\"<%=request.getContextPath()%>/productServlet?method=getOneProduct&pid=${i.pid}\" style=\"color:green\">"+ele.pname+"</a></p><p><font color=\"#FF0000\">商城价：&yen;"+ele.shop_price+"</font></p></div>"
							});
							$("#pageProduct").html(str);
							var str2 = "";
							if(data.obj.currentPage>1){
								str2+="<li><a href=\"<%=request.getContextPath()%>/list.jsp?pagenum="+(data.obj.currentPage-1)+"&search="+HM.getParameter("search")+"\" aria-label=\"Previous\"><span aria-hidden=\"true\">&laquo;</span></a></li>";
							}else{
								str2+="<li><a href=\"<%=request.getContextPath()%>/list.jsp?pagenum=1&search="+HM.getParameter("search")+"\" aria-label=\"Previous\"><span aria-hidden=\"true\">&laquo;</span></a></li>";
							}

							for(var i = 1;i<=data.obj.totalPage;i++){
								if(i==data.obj.currentPage){
									str2+="<li class=\"active\"><a href=\"<%=request.getContextPath()%>/list.jsp?pagenum="+i+"&search="+HM.getParameter("search")+"\">"+i+"</a></li>";
								}else{
									str2+="<li><a href=\"<%=request.getContextPath()%>/list.jsp?pagenum="+i+"&search="+HM.getParameter("search")+"\">"+i+"</a></li>";
								}
							}

							if(data.obj.currentPage<data.obj.totalPage){
								str2+="<li><a href=\"<%=request.getContextPath()%>/list.jsp?pagenum="+(data.obj.currentPage+1)+"&search="+HM.getParameter("search")+"\" aria-label=\"Next\"><span aria-hidden=\"true\">&raquo;</span></a></li>";
							}
							else{
								str2+="<li><a href=\"<%=request.getContextPath()%>/list.jsp?pagenum="+(data.obj.totalPage)+"&search="+HM.getParameter("search")+"\" aria-label=\"Next\"><span aria-hidden=\"true\">&raquo;</span></a></li>";
							}
							$("#pagination").html(str2);
					});
				}
			});

		</script>
	</head>

	<body>
			<div class="container-fluid"  style="max-width: 1370px;">
			<div id="header" style="min-height: 130px;"><jsp:include page="/header.jsp" /></div>
			<div class="container" style="max-width:1370px;width:100%;">
				<div class="row" style="max-width:1370px;width:100%;margin:0 auto;" id="pageProduct">
					<c:forEach items="${pb.list}" var="i" >
						<div style="height:250px;text-align: center;" class="col-md-2 col-sm-4 col-xs-6">
							<a href="<%=request.getContextPath()%>/productServlet?method=getOneProduct&pid=${i.pid}"><img src="${i.pimage}" width="170" height="170" style="display: inline-block;"></a>
							<p><a href="<%=request.getContextPath()%>/productServlet?method=getOneProduct&pid=${i.pid}" style="color:green">${i.pname}</a></p>
							<p><font color="#FF0000">商城价：${i.shop_price}</font></p>
						</div>
					</c:forEach>
				</div>
		
				<!--分页 -->
				<div style="width:380px;margin:0 auto;margin-top:50px; text-align: center;">
					<ul id="pagination" class="pagination" style="text-align:center; margin-top:10px;" id="flip">
						<!--分页<li class="active"><a href="#">1</a></li>-->
						<c:if test="${pb.currentPage>1}">
							<li><a href="<%=request.getContextPath()%>/productServlet?method=getPageProduct&cid=${cid}&pagenum=${pb.currentPage-1}" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
						</c:if>
						<c:if test="${pb.currentPage<=1}">
							<li><a href="<%=request.getContextPath()%>/productServlet?method=getPageProduct&cid=${cid}&pagenum=1" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
						</c:if>

						<c:forEach begin="1" end="${pb.totalPage}" var="i" >
							<c:if test="${pb.currentPage==i}">
								<li class="active"><a href="<%=request.getContextPath()%>/productServlet?method=getPageProduct&cid=${cid}&pagenum=${i}">${i}</a></li>
							</c:if>
							<c:if test="${pb.currentPage!=i}">
								<li><a href="<%=request.getContextPath()%>/productServlet?method=getPageProduct&cid=${cid}&pagenum=${i}">${i}</a></li>
							</c:if>
						</c:forEach>

						<c:if test="${pb.currentPage<pb.totalPage}">
							<li><a href="<%=request.getContextPath()%>/productServlet?method=getPageProduct&cid=${cid}&pagenum=${pb.currentPage+1}" aria-label="Next"><span aria-hidden="true">&raquo;</span></a></li>
						</c:if>
						<c:if test="${pb.currentPage>=pb.totalPage}">
							<li><a href="<%=request.getContextPath()%>/productServlet?method=getPageProduct&cid=${cid}&pagenum=${pb.totalPage}" aria-label="Next"><span aria-hidden="true">&raquo;</span></a></li>
						</c:if>

					</ul>
				</div>
				<div style="width:100%;margin:0 auto; padding: 0 9px;border: 1px solid #ddd;border-top: 2px solid #999;height: 246px;">
		
					<h4 style="width: 50%;float: left;font: 30px 微软雅黑;">浏览记录</h4>
					<div style="width: 50%;float: right;text-align: right;"><a href="">more</a></div>
					<div style="clear: both;"></div>
		
					<div style="overflow: hidden;">
		
						<ul style="list-style: none;">
							<li style="width: 150px;height: 216px;float: left;margin: 0 8px 0 0;padding: 0 18px 15px;text-align: center;"><img src="<%=request.getContextPath()%>/resources/products/1/cs10001.jpg" width="130px" height="130px" /></li>
						</ul>
		
					</div>
				</div>
			</div>
			<div id="footer"  style="min-height: 203px;"><jsp:include page="/foot.jsp" /></div>
		</div>
	</body>

</html>